package easy;

public class Solution_876 {

    public ListNode middleNode(ListNode head) {
        int midCount = 1, headCount = 1;
        ListNode mid = head;
        while (head != null) {
            if (midCount << 1 <= headCount) {
                midCount++;
                mid = mid.next;
            }
            head = head.next;
            headCount++;
        }
        return mid;
    }

    public static void main(String[] args) {
        Solution_876 model = new Solution_876();
        ListNode node = new ListNode(1);
        node.next = new ListNode(2);
        node.next.next = new ListNode(3);
        node.next.next.next = new ListNode(4);
        node.next.next.next.next = new ListNode(5);
        node.next.next.next.next.next = new ListNode(6);
        System.out.println(model.middleNode(node).val);
    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
